#include <iostream>
#include <vector>
using namespace std;
int n, m;
const int N = 110;
vector<vector<char>> arr;
int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int counts;
void dfs(int x, int y)
{
    if (x < 0 || x >= n || y < 0 || y >= m || arr[x][y] == '.') 
        return;
    arr[x][y] = '.';
    for (int i = 0; i < 8; i++)
    {
        int a = x + dx[i];
        int b = y + dy[i];
        dfs(a, b);
    }
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    arr.resize(n, vector<char>(m));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> arr[i][j];
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (arr[i][j] == 'W')
            {
                counts++;
                dfs(i, j);
            }
        }
    }
    cout << counts << endl;
    return 0;
}